<template>
	<view class="poster-content">
		<view v-if="source == 'qssq'"></view>
		<yk-header :title="title" @headBtn="headBtn()" @closePage="closePage()" v-else></yk-header>
		<view class="info">
			<view class="name">{{infoKind.title}}</view>
			<view class="time">{{infoKind.createTime}}</view>
			<!-- <view class="text" id="text" v-html='textUrl'></view> -->
			<!-- <rich-text :nodes="textUrl"></rich-text> -->

			<view class="xq-info" v-if="textUrl">
				<u-parse :content="textUrl" @preview="preview" @navigate="navigate"></u-parse>
			</view>

			<!-- <view class="title-image" @click="imgsmax($event)" :data-url='infoKind.url'>
				<image :src="infoKind.url" mode="widthFix"></image>
			</view> -->
		</view>

		<view v-if="version == 1 || source == 'qssq'"></view>
		<view class="btn-box" v-else>
			<view @click="share">分享</view>
		</view>
	</view>
</template>

<script>
	// import uParse from '@/components/u-parse/u-parse.vue'
	import uParse from './u-parse/parse.vue';
	let url = '';
	let u = ''
	let textUrl1 = '';
	export default {
		data() {
			return {
				title: "文章详情",
				id: "",
				titles: '',
				version: 0,
				infoKind: {},
				xq: '',
				img: '',
				textUrl1: '',
				source: '',
				textUrl: ''
			};
		},
		components: {
			uParse
		},
		onLoad(event) {
			// console.log(event);
			this.id = event.id;
			this.version = window.version;
			this.articleInfo();

		},
		onShow() {
			window.genVersion();
			this.genUrlData();
			this.id = this.id;
			this.img = this.img;
			this.titles = this.titles;
			url = window.location.href;
		},
		methods: {
			preview(src, e) {
				// do something
			},
			navigate(href, e) {
				// do something
			},
			genUrlData() {
				let url = window.location.href;
				let reg_url = /^[^\?]+\?([\w\W]+)$/,
					reg_para = /([^&=]+)=([\w\W]*?)(&|$|#)/g,
					arr_url = reg_url.exec(url),
					ret = {};
				if (arr_url && arr_url[1]) {
					let str_para = arr_url[1],
						result;
					while ((result = reg_para.exec(str_para)) != null) {
						ret[result[1]] = result[2];
					}
				}
				this.source = ret.source;
				console.log('this.source===' + this.source);

			},
			//顶部功能键
			headBtn(e) {
				let that = this;
				uni.showActionSheet({
					itemList: ["刷新", "清除缓存"],
					success: function(res) {
						console.log("选中了第" + (res.tapIndex + 1) + "个按钮");
						if (res.tapIndex == 0) {
							//刷新
							uni.showLoading({
								title: "刷新中"
							});
							setTimeout(function() {
								uni.hideLoading();
							}, 1500);
						} else {
							//清楚缓存
							// callNative('onClearH5Cache')
							uni.showToast({
								title: "清除缓存成功"
							});
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			//接口
			articleInfo() {
				try {
					uni.request({
						url: this.$usereq + "/coupon-admin/zy/article/info/" + this.id,
						method: "GET",
						header: {
							"blade-auth": decodeURI(uni.getStorageSync("token")),
							"content-type": "application/json"
						},
						data: {
							id: this.id
						},
						success: res => {
							let datas = res.data;
							console.log(datas);
							if (datas.code == 200) {
								this.infoKind = datas.data;
								console.log(this.infoKind);
								this.titles = datas.data.title;
								this.img = datas.data.url;
								var textUrl= datas.data.textUrl;

								this.textUrl = datas.data.textUrl;
								textUrl1= (datas.data.textUrl).split('>')[1].split('<')[0].split('<span')[0].split('span>')[0].split('<strong>')[0].split('</strong>')[0];
								 console.log(textUrl1);

							} else {
								uni.showToast({
									title: datas.msg,
									icon: "none",
									duration: 2000
								});
							}
							uni.stopPullDownRefresh();
						}
					});
				} catch (e) {
					console.log(e.message);
				}
			},

			//关闭当前页面
			closePage() {
				callNative("navigateBack");
			},
			share() {
				// let url = window.location.href
				console.log("share img bw===" + url + '&source=qssq' + "====img====" + this.img + '===titles===' + this.titles +
					'===textUrl===' + this.titles);
				onShare(url + '&source=qssq', this.titles, this.img, this.titles);
			},

			// imgsmax(e){
			// 	console.log(e);
			// 	let me=this;
			// 	let imgs=[];
			// 	imgs.push(e.currentTarget.dataset.url);
			// 	console.log(imgs);
			// 	uni.previewImage({
			// 		urls:imgs,
			// 		longPressActions: {
			//     		itemList: ['发送给朋友', '保存图片', '收藏'],
			// 			success: function(data) {
			// 				console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
			// 			},
			// 			fail: function(err) {
			// 				console.log(err.errMsg);
			// 			}
			// 		}
			// 	});
			// }
		}
	}
</script>

<style lang="scss">
	@import './u-parse/parse.css';

	.poster-content {
		width: 100%;
		min-width: 750px;
		font-size: 36px;


		// image {
		// 	width:355px;
		// 	height:378px;
		// 	margin-bottom: 150px;
		// 	display: block;
		// }

		image {
			width: 100%;
			height: 100%;
			background-size: auto;
			margin-bottom: 150px;
			display: block;
		}

		.btn-box {
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 100px;
			overflow: auto;
			text-align: center;

			view {
				float: left;
				line-height: 100px;
				width: 100%;
				color: #fff;
			}

			view:nth-child(1) {
				background: #4db6ff;
			}

			view:nth-child(2) {
				background: #0096ff;
			}
		}

		.info {
			padding: 0 26px;
			height: 100%;

			.name {
				color: #333;
				font-size: 38px;
				width: 100%;
				padding: 26px 0;
			}

			.time {
				color: rgba(0, 0, 0, 0.447058823529412);
				font-size: 24px;
			}

			.xq-info {
				margin-top: 50px;
			}

			// .text {
			// 	padding: 50px 0;
			// }

			.title-image {
				image {
					background-size: auto;
				}
			}
		}
	}
</style>
